package xcmg.device.web.packageSpec;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xcmg.device.dao.entity.packageSpec.PackageSpecDO;
import xcmg.device.infra.BasicController;
import xcmg.device.infra.ErrorCode;
import xcmg.device.service.packageSpec.PackageSpecService;
import yb.ecp.fast.infra.annotation.FastMappingInfo;
import yb.ecp.fast.infra.infra.ActionResult;
import yb.ecp.fast.infra.infra.SearchCommonVO;

import java.util.Date;

/**
 * @author ZHANGK
 * @date 2020/12/14
 **/
@RestController
@RequestMapping("/packageSpec")
public class PackageSpecController extends BasicController {

    @Autowired
    PackageSpecService packageSpecService;

    @ApiOperation(value = "包装箱规格列表")
    @FastMappingInfo(needLogin = true)
    @PostMapping("/list")
    public ActionResult list(@RequestBody SearchCommonVO<PackageSpecDO> condition) throws Exception {
        if (condition.getFilters()==null){
            condition.setFilters(new PackageSpecDO());
        }
        condition.getFilters().setOrgId(getOrgId());
        return actionValueResult(packageSpecService.list(condition));
    }

    @ApiOperation(value = "包装箱新增")
    @FastMappingInfo(needLogin = true)
    @PostMapping("/add")
    public ActionResult add(@RequestBody PackageSpecDO packageSpecDO) throws Exception {
        packageSpecDO.setCreateId(getUserId());
        packageSpecDO.setCreateName(getUserName());
        packageSpecDO.setCreateTime(new Date());
        packageSpecDO.setOrgId(getOrgId());
        return actionResult(packageSpecService.add(packageSpecDO));
    }

    @ApiOperation(value = "包装箱修改")
    @FastMappingInfo(needLogin = true)
    @PostMapping("/update")
    public ActionResult update(@RequestBody PackageSpecDO packageSpecDO){
        return actionResult(packageSpecService.update(packageSpecDO));
    }

    @ApiOperation(value = "包装箱查看")
    @FastMappingInfo(needLogin = true)
    @GetMapping("/item")
    public ActionResult item(String id) throws Exception {
        String orgId = getOrgId();
        return actionResult(ErrorCode.Success,packageSpecService.item(id,orgId));
    }


    @ApiOperation(value = "包装箱全部列表")
    @FastMappingInfo(needLogin = true)
    @GetMapping("/listAll")
    public ActionResult listAll() throws Exception {
        return actionValueResult(packageSpecService.listAll(getOrgId()));
    }

}
